package com.lims.core.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.ServletRequestUtils;

import javacommon.base.BaseStruts2Action;
import javacommon.base.ListRange;
import javacommon.util.TextTool;


import cn.org.rapid_framework.page.Page;

import com.lims.admin.model.User;
import com.lims.core.service.LandInfoManager;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**
 * 土地相关信息汇总展示
* 项目名称：LIMS_v1   
* 类名称：LandInfoAction   
* 类描述：   
* 创建人：zangzh   
* 创建时间：2013-7-10 下午09:58:02   
* 修改人：zangzh   
* 修改时间：2013-7-10 下午09:58:02   
* 修改备注： 
* @version
 */
@SuppressWarnings({ "unchecked", "serial" })
public class LandInfoAction extends BaseStruts2Action implements Preparable,ModelDriven{
	
	//forward paths
	protected static final String LandMain_JSP= "/pages/core/land.jsp";
	protected static final String List_JSP= "/pages/core/landInfoList.jsp";
	protected static final String ListMap_JSP= "/pages/core/landInfoMap.jsp";
	protected static final String SessionOut_JSP = "/commons/sessionOut.jsp";
	protected static final String Unauthorized_JSP = "/commons/unauthorized.jsp";
	protected static final String LandMoreInfo = "/pages/core/landMoreInformation.jsp";
	protected static final String LandImg = "/pages/core/landImage.jsp";
	protected static final String LandCAD = "/pages/core/landCAD.jsp";
	
	public void prepare() throws Exception {}
	public Object getModel() {return null;}
	
	private LandInfoManager landInfoManager;
	public void setLandInfoManager(LandInfoManager landInfoManager) {
		this.landInfoManager = landInfoManager;
	}
	/** 菜单--》土地信息  主页面 */
	public String show() {
		return LandMain_JSP;
	}
	/**进入列表页面**/
	public String list() {
		String corpno = this.getRequest().getParameter("corpno");
		//取得当前用户
		Object obj = this.getRequest().getSession().getAttribute("user");
		User u = null;
		if(obj != null) {
			u = (User)obj;
			if(TextTool.isNull(corpno)) {
				this.getRequest().setAttribute("corpno", u.getCorp().getCorpno());
			} else {
				this.getRequest().setAttribute("corpno", corpno);
			}
		}else {
			return SessionOut_JSP;
		}
		return List_JSP;
	}
	
	/**进入地图页面**/
	public String listMap() {
		String corpno = this.getRequest().getParameter("corpno");
		//取得当前用户
		Object obj = this.getRequest().getSession().getAttribute("user");
		User u = null;
		if(obj != null) {
			u = (User)obj;
			if(u.getCorpnoList().contains(corpno)) {
				List landList = this.landInfoManager.findLandByCorpno(corpno);
				this.getRequest().setAttribute("landList", landList);
			} else {
				return Unauthorized_JSP;
			}
		} else {
			return SessionOut_JSP;
		}
		return ListMap_JSP;
	}
	
	/**执行搜索  土地信息list**/
	public String findList() {
		HttpServletRequest request = this.getRequest();
		String corpno = request.getParameter("corpno");
		int pageNumber = ServletRequestUtils.getIntParameter(request, "page", 1);
		int pageSzie = ServletRequestUtils.getIntParameter(request, "rows", 10);
		Page page = new Page(pageNumber,pageSzie,100);
		ListRange listRange = this.landInfoManager.findLandByCorp(corpno,this.getRequest().getSession(),page);
		this.responseOutWithJson(listRange);
		return null;
	}
	
	/****进入详细信息****/
	public String showLandAll(){
		String landno = ServletRequestUtils.getStringParameter(this.getRequest(), "landno",null);
		Map map = this.landInfoManager.findLandAllByLandno(landno);
		this.requestMap.put("map", map);
		this.requestMap.put("landno", landno);
		return LandMoreInfo;
	}
	/*******进入现场图片或CAD图片*********/
	public String showImg() {
		String landno = ServletRequestUtils.getStringParameter(this.getRequest(), "landno",null);
		//int fileType = ServletRequestUtils.getIntParameter(this.getRequest(), "fileType",0);
		List list = this.landInfoManager.findLandFileByLandAndType(landno,1);
		this.requestMap.put("landFiles", list);
		return LandImg;
	}
	
	public String showCAD() {
		String landno = ServletRequestUtils.getStringParameter(this.getRequest(), "landno",null);
		//int fileType = ServletRequestUtils.getIntParameter(this.getRequest(), "fileType",0);
		List list = this.landInfoManager.findLandFileByLandAndType(landno,2);
		this.requestMap.put("landFiles", list);
		return LandCAD;
	}
}
